layui.define(['form', 'laydate', 'table'], function (exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var comprehensiveQueryTable = null;
    var index = layer.load(1); //添加laoding,0-2两种方式
    var view = {
        init: function () {
            this.initTable();
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function () {
                Lib.doSearchForm($("#searchForm"), comprehensiveQueryTable)
            }
        },
        initTable: function () {
            comprehensiveQueryTable = table.render({
                elem: '#comprehensiveQueryTable',
                height: Lib.getTableHeight(1),
                cellMinWidth: 100,
                method: 'post',
                url: Common.ctxPath + '/cms/comprehensiveQuery/list.json', // 数据接口
                page: Lib.tablePage, // 开启分页
                limit: 10,
                done:function (res) {   //返回数据执行回调函数
                    layer.close(index);    //返回数据关闭loading
                },
                cols: [[ // 表头
                    {
                        type: 'checkbox',
                        fixed: 'left',
                    },
                    {
                        field: 'name',
                        title: '姓名',
                        align: 'center',
                        width:"100"
                    },
                    {
                        field: 'identificationNumber',
                        title: '证件号码',
                        align: 'center',
                        width:"180"
                    },
                    {
                        field: 'currentWorkingEnterprise',
                        title: '工作企业',
                        align: 'center',
                        width:"200"
                    },
                    {
                        field: 'declareTypeText',
                        title: '业务类型',
                        align: 'center',
                        width:"100"
                    },
                    {
                        field: 'businessState',
                        title: '业务状态',
                        align: 'center',
                        width:"120"
                    },
                    {
                        field: 'processResult',
                        title: '审核结果',
                        align: 'center',
                        width:"120"
                    },
                    {

                        field: 'year',
                        title: '年度',
                        align: 'center',
                        width:"80"
                    },{

                        field: 'declareTime',
                        title: '申报时间',
                        align: 'center',
                        width:"180"
                    },{

                        field: 'amount',
                        title: '申报金额',
                        align: 'center',
                        width:"120"
                    },
                    {
                        field: 'handlingSuggestion',
                        title: '审核意见',
                        align: 'center',
                        width:"330"
                    },
                    {
                        field: 'externalTaskId',
                        title: '申报流水号',
                        align: 'center',
                        width:"180"
                    }
                    /*{

                        field: 'organizationCode',
                        title: '统一社会信用代码',
                        align: 'center',
                        width:"135"
                    },*/

                ]]

            });

            table.on('checkbox(comprehensiveQueryTable)', function (obj) {
                var comprehensiveQuery = obj.data;
                if (obj.checked) {
                    //按钮逻辑Lib.buttonEnable()
                } else {

                }
            })
        },

        initSearchForm: function () {
            Lib.initSearchForm($("#searchForm"), comprehensiveQueryTable, form);
        },
        initToolBar: function () {
            toolbar = {
                view: function () { // 获取选中数目
                    var data = Common.getOneFromTable(table, "comprehensiveQueryTable");
                    if (data == null) {
                        return;
                    }
                    var url = "/cms/comprehensiveQuery/edit.do?id=";
                    switch (data.declareType) {
                        case Common.businessType.industrialTalents:
                            url = "/cms/industrialTalents/findenterprise.do?id=";
                            break;
                        case Common.businessType.preparatoryTalent:
                            url = "/cms/preparatoryTalent/findenterprise.do?id=";
                            break;
                        case Common.businessType.BUYHOUSE:
                            url = "/cms/buyHouseSubsidies/findenterprise.do?id=";
                            break;
                        case Common.businessType.skill:
                            url = "/cms/skill/findenterprise.do?id=";
                            break;
                        case Common.businessType.professionalTechnology:
                            url = "/cms/professionalTechnology/findenterprise.do?id=";
                            break;
                        case Common.businessType.renting:
                            url = "/cms/renting/findenterprise.do?id=";
                            break;
                        case Common.businessType.doctoralSubsidy:
                            url = "/cms/doctoralSubsidy/findenterprise.do?id=";
                            break;
                        case Common.businessType.outboundSubsidy:
                            url = "/cms/outboundSubsidy/findenterprise.do?id=";
                            break;
                        case Common.businessType.highlevelTalents:
                            url = "/cms/highlevelTalents/findenterprise.do?id=";
                            break;
                        case Common.businessType.siteFunds:
                            url = "/cms/siteFunds/findenterprise.do?id=";
                            break;
                        case Common.businessType.quit:
                            url = "/cms/quit/findenterprise.do?id=";
                            break;
                        case Common.businessType.entry:
                            url = "/cms/entry/findenterprise.do?id=";
                            break;
                        case Common.businessType.keyInformation:
                            url = "/cms/keyInformation/findenterprise.do?id=";
                            break;
                        case Common.businessType.medicalCare:
                            url = "/cms/medicalCare/findenterprise.do?id=";
                            break;

                    }
                    url = url + data.id;
                    Common.openDlg(url, "查看");
                },
                process: function () { // 获取选中数目
                    var data = Common.getOneFromTable(table, "comprehensiveQueryTable");
                    if (data == null) {
                        return;
                    }
                    var url = "/cms/businessProcess/index.do?businessType=" + data.declareType + "&businessId=" + data.id;
                    Common.openDlg(url, "流程信息>编辑");
                },
                blakInitStatus:function(){
                    // 获取选中数目 - 一次只能操作一条数据
                    var data = Common.getOneFromTable(table, "comprehensiveQueryTable");
                    if (data == null) {
                        return;
                    }
                    if(data.businessState != "业务生效"){
                        Common.alert("当前业务状态不支持该操作,业务生效的记录才能操作！");
                        return;
                    }
                    var url = "/cms/comprehensiveQuery/blakInitStatus.do?businessType=" + data.declareType + "&businessId=" + data.id;
                    Common.post(url, "",function(data){
                        Common.info("成功");
                        dataReload();
                    });
                },
                exportDocument: function () {
                    layui.use(['comprehensiveQueryApi'], function () {
                        var comprehensiveQueryApi = layui.comprehensiveQueryApi
                        Common.openConfirm("确认要导出这些ComprehensiveQuery数据?", function () {
                            comprehensiveQueryApi.exportExcel($("#searchForm"), function (fileId) {
                                Lib.download(fileId);
                            })
                        })
                    });
                },
                importDocument: function () {
                    var uploadUrl = Common.ctxPath + "/cms/comprehensiveQuery/excel/import.do";
                    //模板,
                    var templatePath = "/cms/comprehensiveQuery/comprehensiveQuery_upload_template.xls";
                    //公共的简单上传文件处理
                    var url = "/core/file/simpleUpload.do?uploadUrl=" + uploadUrl + "&templatePath=" + templatePath;
                    Common.openDlg(url, "ComprehensiveQuery>上传");
                }
            };
            $('.ext-toolbar').on('click', function () {
                var type = $(this).data('type');
                toolbar[type] ? toolbar[type].call(this) : '';
            });
        }
    }
    exports('index', view);

});